<template>
    <div>
        <h2>房号列表</h2>
        房号：<input type="text" v-model="sate.name" />
        创建人：<input type="text" v-model="sate.man" />
        <input type="button" value="查询" @click="getlist" />
        <table class="table table-bordered">
            <tr>
                <td>ID</td>
                <td>房号</td>
                <td>创建人</td>
                <td>房型</td>
                <td>房态</td>
                <td>状态</td>
                <td>操作</td>
            </tr>
            <tr v-for="item in list">
                <td>{{ item.id }}</td>
                <td>{{ item.hName }}</td>
                <td>{{ item.man }}</td>
                <td>{{ item.hType }}</td>
                <td>{{ item.hState }}</td>
                <td>{{ item.states == 1 ? '启用' : '禁用' }}</td>
                <td>
                    <input type="button" v-if="item.states == 1" value="禁用" @click="upd(item.id, item.states)" />
                    <input type="button" v-else value="启用" @click="upd(item.id, item.states)" />
                </td>
            </tr>
        </table>
    </div>
</template>

<script setup lang="ts">
import { onMounted, reactive, toRefs } from 'vue';
import axios from 'axios';
import { useRouter, useRoute } from 'vue-router';
let router = useRouter()
let data: any = reactive({
    sate: {
        name: "",
        man: ""
    },
    list: []
})
let { sate, list } = toRefs(data)
onMounted(() => {
    getlist()
})
const getlist = () => {
    let obj = {
        name: sate.value.name,
        man: sate.value.man
    }
    console.log(obj)
    axios({
        url: '/api/HouseNumber/GetHouseNumbers',
        method: 'get',
        params: obj
    })
        .then(res => {
            console.log(res)
            list.value = res.data.data
        })
        .catch(err => {
            console.log(err)
        })
}
const upd = (id: any, state: any) => {
    if (state == 1) {
        state = 0;
    }
    else {
        state = 1;
    }
    let obj = {
        id: id,
        state: state
    }
    console.log(obj)
    axios({
        url: '/api/HouseNumber/UpdState',
        method: 'post',
        params: obj
    })
        .then(res => {
            console.log(res)
            if (res.data.data) {
                alert("修改成功")
                getlist()
            }
        })
        .catch(err => {
            console.log(err)
        })
}

</script>

<style scoped></style>